function customPromiseAll(promises) {
    return new Promise((resolve, reject) => {
        let completedCount = 0;
        const results = [];

        if (promises.length === 0) {
            resolve(results);
            return;
        }

        promises.forEach((promise, index) => {
            Promise.resolve(promise)
                .then(result => {
                    results[index] = result;
                    completedCount++;

                    if (completedCount === promises.length) {
                        resolve(results);
                    }
                })
                .catch(reject);
        });
    });
}
function deepCopy(obj) {
    if (typeof obj !== 'object' || obj === null) {
        // 如果不是对象或者是null，则直接返回
        return obj;
    }

    let copy;
    if (Array.isArray(obj)) {
        // 如果是数组，则创建一个新的数组
        copy = [];
        for (let i = 0; i < obj.length; i++) {
            copy[i] = deepCopy(obj[i]);
        }
    } else {
        // 如果是对象，则创建一个新的对象
        copy = {};
        for (let key in obj) {
            console.log(obj.hasOwnProperty(key), key)
            if (obj.hasOwnProperty(key)) {
                copy[key] = deepCopy(obj[key]);
            }
        }
    }
    console.log(copy, '1')
    return copy;
}
deepCopy({ a: 1, b: { c: 1 } })


function deepCopy(obj) {
    if (typeof obj != 'object' || obj == null) {
        return obj
    }
    let copy
    if (obj instanceof Array) {
        let copy = []
        for (let i = 0; i < obj.length; i++) {
            copy[i] = deepCopy(obj[i])
        }
    } else {
        let obj = {}
        for (let i in obj) {
            if (obj.hasOwnProperty(i)) {
                obj[i] = deepCopy(obj[i])
            }
        }
    }
    return copy
}


function myPromiseAll(arr) {
    return Promise((resolve, reject) => {
        let result = []
        arr.forEach((item) => {
            resolve(item)
                .then(
                    res => {
                        result.push(res)
                        if (result.length == arr.length) {
                            resolve(result)
                        }
                    }
                )
                .catch((err) => {
                    reject(err)
                })
        })
        resolve(result)
    })
}